package com.fldx.baseboot.web.domain;

//import jakarta.persistence.Column;
//import jakarta.persistence.Entity;
import com.fldx.baseboot.common.core.domain.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.format.annotation.DateTimeFormat;

import jakarta.persistence.*;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

@EqualsAndHashCode(callSuper = true)
@Data
@Entity
public class EmailInfo extends BaseEntity {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    protected Long id;
    private String fromUser;
    private String subject;
    @Column(length = Integer.MAX_VALUE)
    private String content;
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime sendTime;
    private String attachment;
    private String attachmentName;
    public void setSendTime(Date sentDate) {
        ZoneId defaultZoneId = ZoneId.systemDefault();
        this.sendTime = LocalDateTime.ofInstant(sentDate.toInstant(), defaultZoneId);
    }

    public void addAttachment(String attachmentName) {
        if(attachment == null || attachment.isEmpty(   )){
            this.attachment = attachmentName;
        }else {
            attachment += "," + attachmentName;
        }
    }
}
